#!/usr/bin/env python

# encoding: utf-8

'''
 * Create File redis_deliver
 * Created by leixu on 2017/10/23
 * IDE PyCharm
'''
import redis

from luobo.component.params_deliver import ParamsDeliver
from luobo.my_config import *


class RedisDeliver(ParamsDeliver):
    def __init__(self, key):
        super().__init__()
        self.key = key
        self.config = None
        self.set_config()
        self.redis = redis.StrictRedis(**self.config)
        self.add_key_to_config({"key": key})

    def get_config(self):
        return self.config

    def set_config(self, config={"host": REDIS_SERVER, "port": REDIS_PORT, "password": "bigdata", "db": 1}):
        self.config = config

    def add_key_to_config(self, config):
        self.config = {**config, **self.config}

    def add_params(self, *args):
        if args:
            self.redis.rpush(self.key, *args)
        else:
            pass

    def get_params(self):
        return self.redis.lpop(self.key)


if __name__ == "__main__":
    r = RedisDeliver("222")
    r.add_params({"dd": "ddd"}, 12, 312, 4, 32, 5, 3, 52, 35)
    while True:
        print(r.get_params())
